﻿using System;
using System.Collections.Generic;

namespace Basefr.Runtime.Extensions
{
    public static class ExceptionExtensions
    {
        public static string GetRecursiveMessage(this Exception exception)
        {
            var messages = new List<string>();

            GetInnerExceptionMsg(exception);

            void GetInnerExceptionMsg(Exception ex)
            {
                if (ex != null)
                {
                    messages.Add(ex.Message);
                    GetInnerExceptionMsg(ex.InnerException);
                }
            }

            return string.Join(" -- ", messages);
        }
    }
}
